package com.maya.controller;


import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.maya.model.Question;
import com.maya.service.QuestionService;



@Controller

public class ViewQuestionController  {

	@Autowired
	private QuestionService questionService;
	
	@RequestMapping("/viewquestion")
    public String viewquestion(String qid,Model model) {
        
      
        Question question = questionService.get(new ObjectId(qid));
        if(null == question) {
            System.out.println("找不到id所对应的question");
            return "notfound";
        }
        
        //通过ID找到对应的问题
        model.addAttribute("question", question);
        
        return "question";
    }
}
